package com.gimi.cloud.bbp.client.controller;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.gimi.cloud.bbp.client.service.SysConfigService;
import com.gimi.cloud.bbp.common.constant.RedisKeyConstant;
import com.gimi.cloud.bbp.common.enums.ResponseCodeEnum;
import com.gimi.cloud.bbp.common.utils.StringUtil;
import com.gimi.cloud.bbp.common.utils.reqhead.Util;
import com.gimi.cloud.bbp.commonService.redis.RedisService;

import net.sf.json.JSONObject;

@Controller
@RequestMapping("/config")
public class SysConfigController {
	
	@Autowired private SysConfigService service;
	@Autowired private RedisService redisService;
	
	/**
	 * 根据KEY获取配置
	 * @param cfKey
	 * @param response
	 */
	@RequestMapping("/getSysConfigValueByCfKey")
	public void getConfigValueByCfKey(@RequestBody String cfKey, HttpServletResponse response) {
		String redisKey = RedisKeyConstant.BBP_CONFIG_PREFIX + cfKey;
		String result = redisService.get(redisKey);
		if (StringUtil.isEmpty(result)) {
			result = service.getConfigValueByCfKey(cfKey);
			redisService.set(redisKey, result);
		}
		Util.sendResponseFastJson(JSONObject.fromObject(result), ResponseCodeEnum.SUCCESSED, response);
	}

}
